﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio;
using System.Runtime.InteropServices;

namespace PovTeam.Pkg_PovrayProject
{
    class PovColorizer : IVsColorizer
    {
        private IVsTextLines pBuffer;

        public PovColorizer(IVsTextLines pBuffer)
        {
            // TODO: Complete member initialization
            this.pBuffer = pBuffer;
        }
        #region IVsColorizer Members

        public void CloseColorizer()
        {
            
        }

        public int ColorizeLine(int iLine, int iLength, IntPtr pszText, int iState, uint[] pAttributes)
        {
            string text = Marshal.PtrToStringUni(pszText);

            // TODO Actual Syntax Highlighting
            bool bComment = false;

            for (int i = 0; i < text.Length; i++)
            {
                pAttributes[i] = 0;
                if ("{}[]+=-~*^<>,.".Contains(text[i]))
                {
                    pAttributes[i] = 2;
                }
                if (bComment || text[i] == '/' && i+1 < text.Length && text[i+1] == '/')
                {
                    pAttributes[i] = 8;
                    bComment = true;
                }
            }

            return 0;
        }

        public int GetStartState(out int piStartState)
        {
            piStartState = 0;
            return VSConstants.S_OK;
        }

        public int GetStateAtEndOfLine(int iLine, int iLength, IntPtr pText, int iState)
        {
            return 0;
        }

        public int GetStateMaintenanceFlag(out int pfFlag)
        {
            pfFlag = 0;
            return VSConstants.S_OK;
        }

        #endregion
    }
}
